home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / ui / tty.c < prev    next >
C/C++ Source or Header  |  1998-08-08  |  3KB  |  166 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15.  
  16. #include "fix.h"
  17. #include "types.h"
  18. #include "gr.h"
  19. #include "ui.h"
  20.  
  21. // ts = total span
  22. // w = width of each item
  23. // n = number of items
  24. // i = item number (0 based)
  25. #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
  26.  
  27. #define BUTTON_HORZ_SPACING 20
  28. #define TEXT_EXTRA_HEIGHT 5
  29.  
  30. int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
  31. {
  32.     UI_WINDOW * wnd;
  33.     UI_GADGET_BUTTON * ButtonG[10];
  34.  
  35.     va_list marker;
  36.     char * Button[10];
  37.  
  38.     short i, width, height, avg, x, y;
  39.     short button_width, button_height, text_height, text_width;
  40.     short w, h;
  41.  
  42.     int choice;
  43.  
  44.     if ((NumButtons < 1) || (NumButtons>10)) return -1;
  45.  
  46.     button_width = button_height = 0;
  47.  
  48.     gr_set_current_canvas( &grd_curscreen->sc_canvas );
  49.  
  50.     va_start( marker, text );
  51.     for (i=0; i<NumButtons; i++ )
  52.     {
  53.         Button[i] = va_arg( marker, char * );
  54.  
  55.  
  56.         ui_get_button_size( Button[i], &width, &height );
  57.  
  58.         if ( width > button_width ) button_width = width;
  59.         if ( height > button_height ) button_height = height;
  60.     }
  61.     va_end( marker );
  62.  
  63.     gr_get_string_size(text, &text_width, &text_height, &avg );
  64.  
  65.     width = button_width*NumButtons;
  66.     width += BUTTON_HORZ_SPACING*(NumButtons+1);
  67.     width ++;
  68.  
  69.     text_width += avg*6;
  70.     text_width += 10;
  71.  
  72.     if (text_width > width )
  73.         width = text_width;
  74.  
  75.     height = text_height;
  76.     height += button_height;
  77.     height += 4*TEXT_EXTRA_HEIGHT;
  78.     height += 2;  // For line in middle
  79.  
  80.     w = grd_curscreen->sc_w;
  81.     h = grd_curscreen->sc_h;
  82.  
  83.     if ( xc == -1 )
  84.         xc = Mouse.x;
  85.  
  86.     if ( yc == -1 )
  87.         yc = Mouse.y - button_height/2;
  88.  
  89.     if ( xc == -2 )
  90.         xc = w/2;
  91.  
  92.     if ( yc == -2 )
  93.         yc = h/2;
  94.  
  95.     x = xc - width/2;
  96.     y = yc - height/2;
  97.  
  98.     if (x < 0 ) {
  99.         x = 0;
  100.     }
  101.  
  102.     if ( (x+width-1) >= w ) {
  103.         x = w - width;
  104.     }
  105.  
  106.     if (y < 0 ) {
  107.         y = 0;
  108.     }
  109.  
  110.     if ( (y+height-1) >= h ) {
  111.         y = h - height;
  112.     }
  113.  
  114.     wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
  115.  
  116.     //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
  117.  
  118.     y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
  119.  
  120.     ui_string_centered( width/2, y, text );
  121.  
  122.     y = 2*TEXT_EXTRA_HEIGHT + text_height;
  123.  
  124.     gr_setcolor( CGREY );
  125.     Hline(1, width-2, y+1 );
  126.  
  127.     gr_setcolor( CBRIGHT );
  128.     Hline(2, width-2, y+2 );
  129.  
  130.     y = height - TEXT_EXTRA_HEIGHT - button_height;
  131.  
  132.     for (i=0; i<NumButtons; i++ )
  133.     {
  134.  
  135.         x = EVEN_DIVIDE(width,button_width,NumButtons,i);
  136.  
  137.         ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i] );
  138.     }
  139.  
  140.     wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
  141.  
  142.  
  143.     choice = 0;
  144.  
  145.     while(choice==0)
  146.     {
  147.         ui_mega_process();
  148.         ui_window_do_gadgets(wnd);
  149.  
  150.         for (i=0; i<NumButtons; i++ )
  151.         {
  152.             if (ButtonG[i]->pressed)   {
  153.                 choice = i+1;
  154.                 break;
  155.             }
  156.         }
  157.  
  158.     }
  159.  
  160.     ui_close_window(wnd);
  161.  
  162.     return choice;
  163.  
  164. }
  165.  
  166.